<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Login Page</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            padding: 20px;
        }
        .container {
            max-width: 300px;
            margin: 0 auto;
        }
        .input-field {
            width: 100%;
            padding: 10px;
            margin: 5px 0;
            border: 1px solid #ccc;
        }
        .button {
            width: 100%;
            padding: 10px;
            background-color: #28a745;
            color: white;
            border: none;
            cursor: pointer;
        }
        .button:hover {
            background-color: #218838;
        }
        .message {
            color: red;
            text-align: center;
        }
    </style>
</head>
<body>
    <div class="container">
        <h2>Login</h2>
        <input type="text" id="username" class="input-field" placeholder="Username" required>
        <input type="password" id="password" class="input-field" placeholder="Password" required>
        <button class="button" onclick="login()">Login</button>
        <p id="message" class="message"></p>
    </div>

    <script>
        async function login() {
            const username = document.getElementById("username").value;
            const password = document.getElementById("password").value;
            const messageElement = document.getElementById("message");

            const response = await fetch("http://127.0.0.1:8000/login", {
                method: "POST",
                headers: {
                    "Content-Type": "application/json"
                },
                body: JSON.stringify({ username, password })
            });

            if (response.ok) {
                const data = await response.json();
                messageElement.style.color = "green";
                messageElement.textContent = data.message;
            } else {
                const data = await response.json();
                messageElement.style.color = "red";
                messageElement.textContent = data.detail;
            }
        }
    </script>
</body>
</html>
